Tests: Add unit tests for is_sitemap() (#51543)#2
Merged
masteradhoc merged 1 commit intoJun 16, 2026
Merged
Conversation
Adds test coverage for the is_sitemap() conditional query tag and the WP_Query::$is_sitemap property introduced for #51543. Tests cover the WP_Query property default, the sitemap index and subtype routes, the sitemap stylesheet route exclusion, is_robots() precedence, the guarantee that a sitemap request is not treated as the home/front page, the global is_sitemap() conditional tag, and the _doing_it_wrong() notice when called before the query is run. Also adds is_sitemap to WP_UnitTestCase::assertQueryTrue() alongside the existing is_robots and is_favicon conditionals for consistency. See #51543.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds unit test coverage for
is_sitemap()from WordPress#12142, targeted at the51543-is-sitemap-conditionalbranch so the tests show up directly in that PR.Trac ticket: https://core.trac.wordpress.org/ticket/51543
What's added
tests/phpunit/tests/query/isSitemap.php— 12 tests (12 assertions, all green locally):WP_Query::$is_sitemapdefaults tofalsesitemap=index) and for subtype routes (e.g.sitemap=posts&sitemap-subtype=post)WP_Query::is_sitemap()returns aboolsitemapquery var does not set the flagsitemap-stylesheet) is not flagged as a sitemapis_robots()takes precedence overis_sitemap()(matching theparse_query()elseifchain)is_sitemap()conditional tag reflects the main query (verified viago_to()+assertQueryTrue())is_sitemap()isfalseon the home pageis_sitemap()triggers_doing_it_wrong()and returnsfalsebefore the query is runIt also adds
is_sitemaptoWP_UnitTestCase::assertQueryTrue()next to the existingis_robots/is_faviconentries, for consistency.Notes for reviewers
go_to()-based tests remove therender_sitemapsaction fromtemplate_redirectso the renderer does notexitmid-test, and create published posts so the request isn't turned into a 404.WP::handle_404()exempts admin/robots/favicon (class-wp.php), but not sitemaps. On a site with zero published posts, a sitemap request falls through toset_404(), which resets$is_sitemapviainit_query_flags(). For normal sites the underlying query returns posts so the flag survives, but it may be worth deciding whetherhandle_404()should also exemptis_sitemap().Test run
PHPCS (
WordPress-Core) clean on both changed files; the existingTests_Query_Conditionalssuite still passes (121 tests) after theassertQueryTrue()addition.